<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>列表</title>
    <script type="text/javascript" src="/js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $(".delete").click(function () {
                var href = $(this).attr("href");
                $("form").attr("action",href).submit();
                alert(href);
                return false;
            });
        });
    </script>
</head>
<body>
<%--删除--%>
<form action="" method="post">
    <input type="hidden" name="_method" value="DELETE">
</form>
<h2>列表</h2>
<c:if test="${empty employees}">
    <span> 没有任何员工信息 </span>
</c:if>
<c:if test="${!empty employees}">
    <table border="1" cellpadding="10" cellspacing="0">
        <tr>
            <th>ID</th>
            <th>LastName</th>
            <th>Email</th>
            <th>Gender</th>
            <th>Department</th>
            <th>Edit</th>
            <th>Delete</th>
        </tr>
        <c:forEach items="${employees}" var="emp">
            <tr>
                <td><a href="/restCrud/emp/detail/${emp.id}">${emp.id}</a></td>
                <td>${emp.lastName}</td>
                <td>${emp.email}</td>
                <td>${emp.gender}</td>
                <td>${emp.department.departName}</td>
                <td><a href="/restCrud/emp/${emp.id}">Edit</a></td>
                <td><a class="delete" href="/restCrud/emp/${emp.id}">Delete</a></td>
            </tr>
        </c:forEach>
    </table>
</c:if>

<h5><a href="/restCrud/emp">Add New Employee</a></h5>

</body>
</html>
